﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using ZhouYu.NewWorld.BLL.IService;
using ZhouYu.NewWorld.Model;
using ZhouYu.NewWorld.ViewModel;

namespace ZhouYu.NewWorld.Web.Controllers
{
    public class VoucherController : Controller
    {
        //注入
        private IVoucherService _voucherService;
        public VoucherController(IVoucherService voucherService)
        {
            _voucherService = voucherService;
        }

        /// <summary>
        /// 抵用卷列表查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        /// <returns></returns>
        public JsonResult GetVouncherList(int page, int limit)
        {
            //创建返回结果对象
            ResponseResult responseResult = new ResponseResult();
            responseResult = _voucherService.GetVouncherList(page, limit);
            return Json(responseResult, JsonRequestBehavior.AllowGet);
        }


        /// <summary>
        /// 删除抵用卷操作记录
        /// </summary>
        /// <param name="vouncherInfo"></param>
        /// <returns></returns>
        public JsonResult DelVoucher(VouncherInfo vouncherInfo)
        {
            //给操作记录对象赋值
            Voucher_record voucher_Record = new Voucher_record();
            voucher_Record.VoucherRecord_Id = vouncherInfo.VoucherRecord_Id;
            //创建返回结果对象
            ResponseResult responseResult = new ResponseResult();
            responseResult = _voucherService.DeleteRecord(voucher_Record);
            return Json(responseResult, JsonRequestBehavior.AllowGet);//JsonRequestBehavior.AllowGet参数：防止数据不安全泄露
        }


        /// <summary>
        /// 删除抵用卷和抵用卷操作记录
        /// </summary>
        /// <param name="vouncherInfo"></param>
        /// <returns></returns>
        public JsonResult DelAllVoucher(VouncherInfo vouncherInfo)
        {
            //给抵用卷对象赋值
            Voucher voucher = new Voucher();
            voucher.Voucher_Id = vouncherInfo.Voucher_Id;
            //创建返回结果对象
            ResponseResult responseResult = new ResponseResult();
            responseResult = _voucherService.DelAllVoucher(voucher);
            return Json(responseResult, JsonRequestBehavior.AllowGet);//JsonRequestBehavior.AllowGet参数：防止数据不安全泄露
        }
        

        /// <summary>
        /// 修改抵用卷信息
        /// </summary>
        /// <param name="vouncherInfo"></param>
        /// <returns></returns>
        public JsonResult EditVoucher(Voucher voucher)
        {
            //创建返回结果对象
            ResponseResult responseResult = new ResponseResult();
            //给修改时间赋值
            voucher.Voucher_UpdateTime = DateTime.Now;
            responseResult.Success = _voucherService.Update(voucher);
            return Json(responseResult, JsonRequestBehavior.AllowGet);//JsonRequestBehavior.AllowGet参数：防止数据不安全泄露
        }


        /// <summary>
        /// 发送抵用卷
        /// </summary>
        /// <param name="vouncherInfo"></param>
        /// <returns></returns>
        public JsonResult AddVoucher(Voucher voucher)
        {
            //创建返回结果对象
            ResponseResult responseResult = new ResponseResult();
            //给修改时间赋值
            voucher.Voucher_UpdateTime = DateTime.Now;
            voucher.Voucher_CreateTime = DateTime.Now;
            responseResult = _voucherService.AddVoucher(voucher);
            return Json(responseResult, JsonRequestBehavior.AllowGet);//JsonRequestBehavior.AllowGet参数：防止数据不安全泄露
        }
    }
}